package frobagroup.controller.backstage;

import frobagroup.entities.backstage.StaffProfile;
import frobagroup.entities.common.Credential;
import frobagroup.services.backstage.StaffSettingsService;
import frobagroup.utils.Constants;
import frobagroup.utils.ResponseModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;

/**
 * Created by Tinsley on 2018/5/10.
 */
@RequestMapping("/webAPI/setting/staff")
@RestController
public class StaffSettingsController {

    @Autowired
    private StaffSettingsService settingsService;

    @RequestMapping(value = "/findProfileById", method = RequestMethod.POST )
    public ResponseEntity<ResponseModel<Object>> findProfileById(HttpServletRequest request
    ) throws ServletException {
        return ResponseModel.success(settingsService.findProfileById((String)request.getAttribute("staffId")),
                Constants.RESPONSE_STATUS_SUCESS);
    }

    @RequestMapping(value = "/updateProfile", method = RequestMethod.POST )
    public ResponseEntity<ResponseModel<Object>> updateProfile(@RequestBody StaffProfile staffProfile, HttpServletRequest request
    ) throws ServletException {
        return ResponseModel.success(settingsService.updateProfile(staffProfile,(String)request.getAttribute("staffId")),
                Constants.RESPONSE_STATUS_SUCESS);
    }

    @RequestMapping(value = "/updateStaffPassword", method = RequestMethod.POST )
    public ResponseEntity<ResponseModel<Object>> updateStaffPassword(@RequestBody Credential credential, HttpServletRequest request
    ) throws ServletException {
        return ResponseModel.success(settingsService.updateStaffPassword(credential,(String)request.getAttribute("staffId")),
                Constants.RESPONSE_STATUS_SUCESS);
    }


}
